package org.bim.view.drag.design.model;

import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * 查询 列表分页
 *
 * @author cbdyzj
 * @since 2018-07-30
 */
@Accessors(chain = true)
@Getter
@Setter
@Builder
public class Page<T> {
    @ApiModelProperty("返回列表")
    private List<T> list;

    @ApiModelProperty("数据总条数")
    private Long total;
    @ApiModelProperty("当前页码数")
    private Integer pageNum;
    @ApiModelProperty("页大小")
    private Integer pageSize;
    @ApiModelProperty("总页数")
    private Integer pageTotal;
    public Page() {
    }
    public Page(List<T> list, int pageNum, int pageSize, Long total) {
        this.list = list;
        this.pageNum = pageNum;
        this.pageSize=pageSize==0?10:pageSize;
        this.total=total;
        this.pageTotal =(int)(total/this.pageSize+1);
    }
    public Page(List<T> list, Long total) {
        this.list = list;
        this.total = total;
        this.pageNum=1;
        this.pageSize=10;
        this.pageTotal =(int)(total/10+1);
    }
    public Page(List<T> list, Long total, Integer pageNo, Integer pageSize, Integer pageTotal) {
        this.list = list;
        this.total = total;
        this.pageNum = pageNo;
        this.pageSize = pageSize;
        this.pageTotal = pageTotal;
    }

    public static <T> Page<T> pageFormat(List<T> list, Integer pageIndex, Integer pageSize, Integer count, Integer pageNum) {
        return new Page<>(list, count.longValue(), pageIndex, pageSize, pageNum);
    }
}
